package com.basker.pisces.springcloud.context;

import com.basker.pisces.context.LoginContext;
import com.basker.pisces.context.LoginContextHolder;
import com.basker.pisces.service.constant.ServiceConstants;

import feign.RequestInterceptor;
import feign.RequestTemplate;

public class TokenRequestInterceptor implements RequestInterceptor {

    private static final String TOKEN_ID_KEY = ServiceConstants.MessageHead.TOKEN_ID_KEY;

    @Override
    public void apply(RequestTemplate template) {
        LoginContext loginContext = LoginContextHolder.getLoginContext();
        if (loginContext != null) {
            template.header(TOKEN_ID_KEY, loginContext.getToken().getTokenId());
        }
    }

}
